import {MainData} from "../../coreModule/data/BaseData";
import {DataOccasion, field, occasion} from "../../coreModule/data/DataLoader";
import {dataClass} from "../../coreModule/managers/DataManager";
import {BaseRepository, getRepository, repository} from "../../coreModule/data/BaseRepository";
import {Constructor} from "../../../utils/BaseContext";
import {iLevelRepo} from "../../userModule/data/Role";

@dataClass("Exam")
export class Exam extends MainData{

	@field(String)
	public levelId: string;
	@field([String])
	public questionIds: string[];
	@field(Number)
	public quesCount: number;
	@field(Number)
	public time: number;
	@field(Number)
	public score: number;
	@field(Number)
	public price: number;

	/**
	 * 等级
	 */
	get level() {
		return iLevelRepo().doc(this.levelId);
	}

	// region 额外信息

	@field(String)
	@occasion(DataOccasion.Extra)
	levelName: string;

	/**
	 * 刷新
	 */
	public refresh() {
		this.levelName = this.level.name;
	}

	// endregion

	/**
	 * 测试数据
	 */
	public static testData(){
		const res = new Exam();
		res.quesCount = 50;
		res.time = 60;
		res.score = 50;

		return res;
	}
}

export function examRepo() {
	return getRepository(ExamRepo);
}

@repository
class ExamRepo extends BaseRepository<Exam> {
	get clazz(): Constructor<Exam> { return Exam; }
	constructor() { super(); }

}

